/*************************************************************************
	> File Name: P1296.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-02-11 09:50:43
 ************************************************************************/
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_N 1000000
int arr[MAX_N + 5];

int binary_search(int l, int r, int d) {
    int head = l, tail = r, mid;
    while (head < tail) {
        mid = (head + tail + 1) >> 1;
        if (arr[mid] - arr[l] <= d) head = mid;
        else tail = mid - 1;
    }
    if (arr[head] - arr[l] > d) return 0;
    return head - l;
}

int main() {
    int n, d;
    cin >> n >> d;
    for (int i = 0; i < n; i++) {
        scanf("%d", arr + i);
    }
    sort(arr, arr + n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += binary_search(i, n - 1, d);
    }
    cout << ans << endl;
    return 0;
}
